package l1j.server.server.command.executor;

import static l1j.server.server.model.skill.L1SkillId.STATUS_CHAT_PROHIBITED;

import java.util.StringTokenizer;

import l1j.opqlo.SuperNGChat;
import l1j.opqlo.Server.L1World.L1World;
import l1j.server.Thread.GeneralThreadPool;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.serverpackets.S_SkillIconGFX;
import l1j.server.server.serverpackets.S_SystemMessage;

public class L1ChatNG implements L1CommandExecutor {

	public static L1CommandExecutor getInstance() {
		return new L1ChatNG();
	}

	private void execute(final L1PcInstance pc , final String name , final int time){
		final L1PcInstance tg = L1World.getInstance().getPlayer(name);
		if (tg != null) {
			tg.setSkillEffect(STATUS_CHAT_PROHIBITED, time * 60 * 1000);
			tg.sendPackets(new S_SkillIconGFX(36, time * 60));
			tg.sendPackets(new S_ServerMessage(286, String.valueOf(time))); // \f3ゲームに適合しない行動であるため、今後%0分間チャットを禁じます。
			pc.sendPackets(new S_ServerMessage(287, name)); // %0のチャットを禁じました。
			final SuperNGChat r = new SuperNGChat(tg , time*60);
			GeneralThreadPool.getInstance().schedule(r, 500);
		}else{
			pc.sendPackets(new S_SystemMessage("角色: "+name+"	不在線上。"));
		}
	}


	// @Override
	@Override
	public void execute(final L1PcInstance pc, final String cmdName, final String arg) {
		try {
			final StringTokenizer st = new StringTokenizer(arg);
			final String name = st.nextToken();
			final int time = Integer.parseInt(st.nextToken());

			if(pc != null){
				this.execute(pc,name , time);
			}else{
				this.execute(name , time);
			}

		} catch (final Exception e) {
			pc.sendPackets(new S_SystemMessage(cmdName + " 玩家名稱 時間（分） 請輸入。"));
		}
	}


	private void execute(final String name , final int time){
		final L1PcInstance tg = L1World.getInstance().getPlayer(name);
		if (tg != null) {
			tg.setSkillEffect(STATUS_CHAT_PROHIBITED, time * 60 * 1000);
			tg.sendPackets(new S_SkillIconGFX(36, time * 60));
			tg.sendPackets(new S_ServerMessage(286, String.valueOf(time))); // \f3ゲームに適合しない行動であるため、今後%0分間チャットを禁じます。
			final SuperNGChat r = new SuperNGChat(tg, time*60);
			GeneralThreadPool.getInstance().schedule(r, 500);
			System.out.println("角色: "+name+"	已被你禁言 "+time+" 分鐘。");
		}else{
			System.out.println("角色: "+name+"	不在線上。");
		}
	}
}
